package com.wisdytech.linkdcs.partLife.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.DataTransformUtil;
import com.wisdytech.linkdcs.equipment.model.Equipment;
import com.wisdytech.linkdcs.partLife.dto.PartRepSearchDTO;
import com.wisdytech.linkdcs.partLife.dto.PartReplaceDTO;
import com.wisdytech.linkdcs.partLife.model.PartReplace;
import com.wisdytech.linkdcs.partLife.service.IPartReplaceService;
import com.wisdytech.linkdcs.partLife.vo.PartRepSearchVO;
import com.wisdytech.linkdcs.partLife.vo.PartReplaceVO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

/**
 * <p>
 *  设备备件更换前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-06-05
 */
@Controller
@RequestMapping("/part/partReplace")
public class PartReplaceController {
	
    @Resource
    private IPartReplaceService iPartReplaceService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "lifeCycle/partLifeCycle/partReplace";
    }
    
    @RequestMapping("/search")
    public String search(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "lifeCycle/partLifeCycle/partReplaceSearch";
    }
    /**
     * <p>Description:查询设备信息列表</p>
     * @param equipName 设备名称
     * @return 设备信息列表集合
     */
    @RequestMapping(value = "/listAllEquipAndPart/get.mvc")
    @ResponseBody
    public StandardResult listAllEquipAndPart(String equipName){
        List<Equipment> list = iPartReplaceService.listAllEquipAndPart(equipName);
        return StandardResult.getSuccessResult(list);
    }
    
    
    /**
     * 分页条件查询备件配置列表信息
     * @param equipId 设备id
     * @param filter 分页参数
     * @return 备件配置管理列表信息
     * @throws IOException 
     */
    @RequestMapping(value = "/listPartRepByFilter/get.mvc")
    @ResponseBody	
    public StandardTableResult<PartReplaceVO> listPartRepByFilter(String equipId,Filter filter) throws IOException{
    	PageInfo<PartReplace> partReplaces =this.iPartReplaceService.listPartRepByFilter(equipId,filter);
        //转换为前台结果集
        List<PartReplace> partReplacesList=partReplaces.getList();
        List<PartReplaceVO> partReplacesVOList=new ArrayList<PartReplaceVO>();
        for(PartReplace partReplace:partReplacesList){
        	partReplacesVOList.add(DataTransformUtil.changePartReplaceVO(partReplace));
        }
        return new StandardTableResult<PartReplaceVO>(partReplaces.getTotal(),partReplacesVOList);
    }
    
    /**
     * <p>Description:查询备件原序列号</p> 
     * @param equipId 设备id
     * @return 序列号信息信息
     */
    @RequestMapping(value = "/getSeriByEquipId/get.mvc")
    @ResponseBody
    public StandardResult getSeriByEquipId(String equipId){
    	PartReplace partReplace = iPartReplaceService.getSeriByEquipId(equipId);
        return StandardResult.getSuccessResult(partReplace);
    }
    
    /**
     * 保存备件更换信息
     * @param partReplaceDTO 备件更换对象
     * @return 保存结果集
     */
    @RequestMapping(value = "/savePartReplace/save.mvc")
    @ResponseBody
    public StandardResult savePartReplace(PartReplaceDTO partReplaceDTO) {
    	//保存更换信息
    	iPartReplaceService.savePartReplace(partReplaceDTO);
        return  StandardResult.getSuccessResult();
    }
    
    
    
    /**
     * 分页条件查询备件更换记录列表信息
     * @param repSearchDTO 查询条件对象
     * @param filter 分页参数
     * @return 备件更换记录列表信息
     * @throws IOException 
     */
    @RequestMapping(value = "/listPartRepAllByFilter/get.mvc")
    @ResponseBody	
    public StandardTableResult<PartRepSearchVO> listPartRepAllByFilter(PartRepSearchDTO repSearchDTO,Filter filter) throws IOException{
    	PageInfo<PartReplace> partReplaces =this.iPartReplaceService.listPartRepAllByFilter(repSearchDTO,filter);
        //转换为前台结果集
        List<PartReplace> partReplacesList=partReplaces.getList();
        List<PartRepSearchVO> partReplacesVOList=new ArrayList<PartRepSearchVO>();
        for(PartReplace partReplace:partReplacesList){
        	partReplacesVOList.add(DataTransformUtil.changePartReplaceAllVO(partReplace));
        }
        return new StandardTableResult<PartRepSearchVO>(partReplaces.getTotal(),partReplacesVOList);
    }
    
    
    /**
     * 分页条件查询备件配置列表信息
     * @param equipCode 设备编码
     * @param search 模糊查询
     * @param filter 分页参数
     * @return 备件更换列表信息
     * @throws IOException 
     */
    @RequestMapping(value = "/listModelPartByFilter/get.mvc")
    @ResponseBody	
    public StandardResult listModelPartByFilter(String equipCode,String search,Filter filter) throws IOException{
    	PageInfo<PartReplace> partReplaces =this.iPartReplaceService.listModelPartByFilter(equipCode,search,filter);
        //转换为前台结果集
        List<PartReplace> partReplacesList=partReplaces.getList();
        List<PartReplaceVO> partReplacesVOList=new ArrayList<PartReplaceVO>();
        for(PartReplace partReplace:partReplacesList){
        	partReplacesVOList.add(DataTransformUtil.changePartReplaceVO(partReplace));
        }
        return StandardResult.getSuccessResult(partReplacesVOList);
    }
    
    
    /**
     * 查询更换的关键备件
     * @param equipCode 设备编码
     * @param partId 设备型号
     * @param localtionId 位置id
     * @param filter 分页参数
     * @return 备件配置管理列表信息
     * @throws IOException 
     */
    @RequestMapping(value = "/getKeyPartByPartId/get.mvc")
    @ResponseBody	
    public StandardResult getKeyPartByPartId(String equipCode,String partId,String localtionId,Filter filter) throws IOException{
    	PartReplace partReplace =this.iPartReplaceService.getKeyPartByPartId(equipCode,partId,localtionId,filter);
    	PartReplaceVO partReplaceVO = new PartReplaceVO();
    	if(partReplace!=null) {
    		partReplaceVO= DataTransformUtil.changePartReplaceVO(partReplace);
    	}
        return StandardResult.getSuccessResult(partReplaceVO);
    }
    
}

